package com.daka.controller;

import com.daka.entity.ActivitySign;
import com.daka.entity.Member;
import com.daka.enumerate.StatusCode;
import com.daka.service.ActivitySignService;
import com.daka.service.MemberService;
import com.daka.vo.request.ActivityVo;
import com.daka.vo.response.DataResponseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yangx
 * CreateTime: 2016/9/22 15:52
 */

@Controller
@RequestMapping("/index")
@Slf4j
public class IndexController {

    @Autowired
    private MemberService memberService;
    @Autowired
    private ActivitySignService activitySignService;

    @ResponseBody
    @RequestMapping(value = "/queryAll", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public DataResponseVo<Object> queryAll(@RequestBody ActivityVo vo) {
        if (vo.getMemberID() == null) {
            return new DataResponseVo<Object>(StatusCode.COMMON_PARAM_ERROR.getCode(), StatusCode.COMMON_PARAM_ERROR.getMessage());
        }
        Map<String, Object> map = new HashMap<String, Object>();
        Member member = memberService.selectByMemberId(vo.getMemberID());
        //总的公益时间
//        map.put("time",member.getVolunteerTime());
        if (member.getAllTimes() != null) {
            map.put("time", member.getAllTimes());
        } else {
            map.put("time", 0);
        }

        //参加的活动次数
        ActivitySign activitySign = new ActivitySign();
        activitySign.setMember(member.getId());
        int activities = activitySignService.selectByStatementCount(activitySign);
        map.put("activities", activities);
        return new DataResponseVo<Object>(StatusCode.OK.getCode(), StatusCode.OK.getMessage(), map);
    }


}
